


const request = require('../../../utils/request');
var page = 1, num = 10, type = 'distance';

function loadingData(that,page,num){
    if(that.data.upflag){
        request.HttpRequst(true,'reserve',false,'',{"lng": that.data.longitude, "lat": that.data.latitude,"page":page,"num": num,"type": type},"GET",false,res => {
            //console.log(res.data)
            if(res.data != ''){
                let goodsData = that.data.goods.concat(res.data)
                that.setData({
                    goods: goodsData
                })
            }else{
                that.setData({
                    upflag: false
                })
            }
        })
    }
    
}

Page({
    data: {
        list:[0,1,2,3,4],
        goods: [],
        latitude: 0,    //纬度
        longitude: 0, //经度
        upflag: true,
        menuIndex:1,
        inputVal:'',
        noFind: '',
        imgUrl:request.imgUrl
    },
    onLoad: function() {
        this.setData({
            latitude: wx.getStorageSync('latitude'),    //纬度
            longitude: wx.getStorageSync('longitude')  //经度
        })
        
    },
    onReady: function(){
        wx.setNavigationBarTitle({
            title: '搜索中心'
        })
    },
    /*下拉获取更多电影数据*/
    onReachBottom:function(){
        var that = this;
        page++;
        loadingData(that,page,num);
    },

    //获取输入的关键字
    getInputVal(e) {
        console.log(e);
        this.setData({
            inputVal: e.detail.value
        })
    },
    
    //搜索
    search() {
        request.HttpRequst(true,'search/shop',false,'',{"s":this.data.inputVal,"lng": this.data.longitude, "lat": this.data.latitude,"page":page,"per_page": num,"type": type},"POST",false,res => {
            console.log(res)
            if(res.code == 200){
                this.setData({
                    noFind: '',
                    goods: res.data.data
                })
            }else{
                this.setData({
                    goods: '',
                    noFind: res.info
                })
            }
            
        })
    },


    //跳到预定
    goShop(e) {
        var id = e.currentTarget.dataset.id
        wx.navigateTo({
            url: '../list/advance/shop/shop?id='+id
        })
    },

    //跳到排队
    goLineShop(e){
        var id = e.currentTarget.dataset.id
        wx.navigateTo({
            url: '../list/line/lineShop/lineShop?id='+id
        })
    }
})